<?
class ScanPermissionForm extends Form
{
	function ScanPermissionForm()
	{
		Form::Form('ScanPermissionForm');

		$this->addPerm();
	}

	function addPerm()
	{
		$res = DB::query("SELECT * FROM module");
		
		$perm= array();

		while($r = @mysql_fetch_assoc($res))
		{
			if($r['name'] != '.svn' && file_exists(DIR_MODULE.$r['name'].'/class.php'))
			{
				require_once DIR_MODULE.$r['name'].'/class.php';

				eval('if(method_exists("'.$r['name'].'","permission"))
					  {
					    $tmp = '.$r['name'].'::permission();

						if($tmp)
						{
							foreach($tmp as $id=>$val)
							{
								unset($tmp["$id"]);
								
								$id = str_replace(\' \',\'_\',$id);
								
								$tmp["$id"] = trim($val);
							}
							
							$perm["'.$r['name'].'"] = $tmp;
						}
					}');
			}
		}
		
		$perm = serialize($perm);

        //DB::insert("configs", array('conf_key' => 'site_permission', 'conf_val' => $perm),true);
        DB::insert("config", array('cf_name' => 'site_permission', 'cf_value' => $perm),true);

        ECLib::get_config(1);
	}
}
?>